<?php
/**
 * Created by PhpStorm.
 * User: mr.lee
 * Date: 2017/6/5
 * Time: 上午9:38
 */

namespace app\api\controller;


use app\common\controller\ActionLogs;
use app\common\model\Agent;
use app\common\model\Merchant;
use app\common\model\Paylog;

class HttpApi
{
    private function getappid($mid)
    {
        $Merchant = new Merchant();
        $agentid = $Merchant->where('id', $mid)->value('agent');
        $Agent = new Agent();
        $appid = $Agent->where('id', $agentid)->value('sign_appid');
        return $appid;


    }

    private function getmerchantname($mid)
    {
        $map['id'] = $mid;
        $name = Merchant::where($map)->value('merchant');
        return $name;

    }

    private function getprintid($mid)
    {

        $map['id'] = $mid;
        $name = Merchant::where($map)->value('agent');
        $agentinfo = Agent::where('id', $name)->find();
        $param['appid'] = $agentinfo['wsy_print_appid'];
        $param['key'] = $agentinfo['wsy_print_key'];
        return $param;

    }

    private function checkparam($param, $type)
    {
        switch ($type) {
            case "pay":
                $sdata = array('merchantId', 'outTradeNo', 'totalFee', 'orderIp', 'authCode', 'channel', 'device_id', 'client_id', 'confirm', 'Version', 'TimeStamp', 'SignatureNonce', 'sign');
                break;
            case "checkpay":
                $sdata = array('merchantId', 'channel', 'device_id', 'client_id', 'Version', 'TimeStamp', 'SignatureNonce', 'sign');
                break;
            case "payrefund":
                $sdata = array('merchantId', 'refundNo', 'refundFee', 'channel', 'Version', 'TimeStamp', 'SignatureNonce', 'sign');
                break;
            case "payrefundquery":
                $sdata = array('merchantId', 'refundNo', 'Version', 'TimeStamp', 'SignatureNonce', 'sign');
                break;

        }
        $arr = array_diff($sdata, $param);
        $arr2 = implode(',', $arr);

        if (!empty($arr2)) {
            $arrs['code'] = "FAIL";
            $arrs['message'] = "缺少参数" . $arr2;
        } else {
            $arrs['code'] = "0";
            $arrs['message'] = "SUCCESS";

        }
        return $arrs;


    }

    public function api($param9 = "")
    {


        try {
            if (empty($param9)) {
                $query_type = request()->get('query_type');

                $postData = file_get_contents('php://input');
            } else {

                $query_types = json_decode($param9, true);
                $query_type = $query_types['query_type'];
//                return $query_type;
                $postData = $param9;
            }

            $param1 = json_decode($postData, true);

            $param = json_decode($postData, true);
            $ActionLogs=new ActionLogs();
            $ActionLogs->writelog("payos","wsylog","logs","接收信息".$query_type,$param);
            $check = $this->checkparam(array_keys($param), $query_type);
            if ($check['code'] == "0") {
                unset($param1['sign']);

//            $param1['appid'] = $this->getappid($param['merchantId']);
                $sign = getsign(uni_array($param1), "MD5", $this->getappid($param['merchantId']));
                if ($sign == $param['sign']) {
                    switch ($query_type) {
                        case "pay":
                            $params['appid'] = $this->getappid($param['merchantId']);
                            $params['merchantid'] = $param['merchantId'];
                            $params['method'] = "pay";
                            $params['trade_no'] = $param['outTradeNo'];
                            $params['source'] = "pc";

                            $params['out_trade_no'] = isset($param['out_trade_no']) ? $param['out_trade_no'] : "";
                            $params['total_fee'] = $param['totalFee'] / 100;
                            $params['client_ip'] = $param['orderIp'];
                            $params['auth_code'] = $param['authCode'];
                            $params['channel'] = $param['channel'];
                            $params['device_id'] = $param['device_id'];
                            $params['pay_cate'] = "pay";
                            $params['client_source'] = 2;
                            $params['goods_detail'] = isset($param['goods_detail']) ? $param['goods_detail'] : "";
                            $params['confirm'] = $param['confirm'];
                            $params['version'] = $param['Version'];
                            $params['timestamp'] = $param['TimeStamp'];
                            $params['signaturenonce'] = $param['SignatureNonce'];


                            break;
                        case "checkpay":
                            $params['merchid'] = $param['merchantId'];
                            $params['type'] = "checkpay";
                            $params['orderid'] = isset($param['tradeNo']) ? $param['tradeNo'] : "";
                            $params['orderid2'] = isset($param['out_transaction_id']) ? $param['out_transaction_id'] : "";
                            $params['wsy_orderid'] = isset($param['outTradeNo']) ? $param['outTradeNo'] : "";
                            if (isset($param['tradeNo'])) {
                                $mab['orderid'] = $param['tradeNo'];
                            } elseif (isset($param['outTradeNo'])) {
                                $mab['trade_no'] = $param['outTradeNo'];

                            } elseif (isset($param['out_transaction_id'])) {
                                $mab['orderid'] = $param['out_transaction_id'];

                            }

                            $orderid = Paylog::where($mab)->value('orderid');
                            $params['appid'] = $this->getappid($param['merchantId']);
                            $params['merchantid'] = $param['merchantId'];
                            $params['method'] = "orderquery";
                            $params['source'] = "pc";
                            $params['out_trade_no'] = $orderid;
                            $params['trade_no'] = $orderid;
                            $params['channel'] = $param['channel'];
                            $params['version'] = $param['Version'];
                            $params['timestamp'] = $param['TimeStamp'];
                            $params['signaturenonce'] = $param['SignatureNonce'];
                            break;
                        case "payrefund":
                            $params['merchantid'] = $param['merchantId'];
                            $params['appid'] = $this->getappid($param['merchantId']);
                            $params['method'] = "orderrefund";
                            $params['source'] = "pc";
                            if (isset($param['tradeNo'])) {
                                $mab['orderid'] = $param['tradeNo'];
                            } elseif (isset($param['outTradeNo'])) {
                                $mab['trade_no'] = $param['outTradeNo'];
                            }
                            $mab['pay_statu'] = ['neq', 0];
                            $orderid = Paylog::where($mab)->value('orderid');
                            $params['out_trade_no'] = $orderid;
                            $params['client_source'] = 2;
                            $params['other_refund_no'] = isset($param['refundNo']) ? $param['refundNo'] : "";
                            $params['channel'] = $param['channel'];
                            $params['device_id'] = "";
                            $params['source'] = "PC";
                            $params['refund_desc'] = $param['channel'];
                            $params['refund_fee'] = $param['refundFee'] / 100;
                            $params['version'] = $param['Version'];
                            $params['timestamp'] = $param['TimeStamp'];
                            $params['signaturenonce'] = $param['SignatureNonce'];
                            break;
                        case "payrefundquery":
                            $params['merchantid'] = $param['merchantId'];
                            $params['appid'] = $this->getappid($param['merchantId']);
                            $params['source'] = "pc";
                            $params['method'] = "orderrefundquery";
                            if (!empty($param['tradeNo'])) {
                                $mab['orderid'] = $param['tradeNo'];
                            } elseif (!empty($param['outTradeNo'])) {
                                $mab['trade_no'] = $param['outTradeNo'];
                            }
                            $Paylog = new Paylog();
                            $id = $Paylog->where($mab)->find();
                            $params['out_trade_no'] = $id['orderid'];
                            $params['refund_no'] = isset($param['refundNo']) ? $param['refundNo'] : "";
                            $params['version'] = $param['Version'];
                            $params['timestamp'] = $param['TimeStamp'];
                            $params['signaturenonce'] = $param['SignatureNonce'];
                            break;


                    }
                    $params['sign'] = getsign(uni_array($params), "MD5", $this->getappid($param['merchantId']));
                    $data2 = $this->http_post('https://api.wunengkeji.com/api.php', json_encode($params));
                    $data = $this->re_param(json_decode($data2, true), $param['merchantId'], $query_type, $param);


                } else {
                    $data['return_code'] = "SUCCESS";
                    $data['result_code'] = "FAIL";
                    $data['result_msg'] = "签名错误";
                    $data['return_msg'] = "签名错误" . $sign;
                }

            } else {
                $data['return_code'] = "SUCCESS";
                $data['result_code'] = "FAIL";
                $data['result_msg'] = $check['message'];
                $data['return_msg'] = $check['message'];
            }

        } catch (\Exception $e) {
            $data['return_code'] = "SUCCESS";
            $data['result_code'] = "FAIL";
            $data['result_msg'] = $e->getMessage();
            $data['return_msg'] = $e->getMessage();
        }

        $ActionLogs->writelog("payos","wsylog","logs","返回信息".$query_type,$data);

        return json_encode($data);


    }

    private function re_param($data, $mid, $type, $param)
    {
//        return $data;

        switch ($type) {
            case "pay":


                if ($data['result_code'] == "SUCCESS") {
//            return 123;
                    $re_param['return_code'] = $data['return_code'];
                    $re_param['result_code'] = $data['result_code'];
                    $re_param['result_msg'] = $data['result_msg'];
                    $re_param['return_msg'] = $data['return_msg'];
                    $re_param['outTradeNo'] = $data['trade_no'];
                    $re_param['tradeNo'] = $data['out_trade_no'];
                    $re_param['dis_card_zk'] = isset($data['dis_card_zk']) ? $data['dis_card_zk'] * 100 : "";//会员卡折扣
                    $re_param['vip_card_zk'] = isset($data['vip_card_zk']) ? $data['vip_card_zk'] * 100 : "";//会员卡等级折扣
                    $re_param['gel_card_zk'] = isset($data['gel_card_zk']) ? $data['gel_card_zk'] * 100 : "";//卡券折扣
                    $re_param['gel_info'] = isset($data['gel_info']) ? $data['gel_info'] : "";    //折扣详情
                    $re_param['totalFee'] = $data['ought_fee'] * 100;//应付
                    $re_param['ought_price'] = $data['total_fee'] * 100;//实付
                    if ($data['channel'] == 2) {
                        $channel = "wx_barcode_pay";
                    } elseif ($data['channel'] == 3) {
                        $channel = "ali_barcode_pay";
                    } elseif ($data['channel'] == 8) {
                        $channel = "card_barcode_pay";
                    }
                    $re_param['channel'] = $channel;


                    $re_param['out_transaction_id'] = $data['out_trade_no'];
                    $re_param['time_end'] = date('YmdHis', strtotime($data['end_time']));
                    $sign = getsign(uni_array($re_param), "MD5", $this->getappid($mid));
                    $re_param['sign'] = $sign;
                    //接口打印开始
                    $paramd['device_id'] = $param['device_id'];
                    $paramd['paytime'] = date('Y-m-d H:i:s', strtotime($data['end_time']));
                    $paramd['merchant'] = $this->getmerchantname($mid);
                    $paramd['out_trade_no'] = $data['trade_no'];
                    $paramd['staff'] = "";
                    $paramd['total_fee'] = $data['total_fee'];
                    if ($data['channel'] == 2) {
                        $channel2 = "微信";
                        $bmp = 1;
                    } elseif ($data['channel'] == 3) {
                        $channel2 = "支付宝";
                        $bmp = 2;
                    } elseif ($data['channel'] == 8) {
                        $channel2 = "会员卡";
                        $bmp = 1;
                    }
                    $paramd['paymode'] = $channel2;
                    $paramd['bmp'] = $bmp;
                    $paramd['yf_price'] = $data['ought_fee'];
                    $paramd['dis_card_zk'] = $re_param['dis_card_zk'];
                    $paramd['vip_card_zk'] = $re_param['vip_card_zk'];
                    $paramd['gel_card_zk'] = $re_param['gel_card_zk'];
                    $paramd['gel_info'] = $re_param['gel_info'];
                    //根据参数获取key
                    $sedata=$paramd;
                    $sedata['client_id']=$param['client_id'];
                    $sedata['device_id']=$param['device_id'];
                    $sedata['mid']=$mid;
                    $JobTask=new JobTask();
                    $s=$JobTask->mss_send_wsy_print($sedata);
//                    $client_id = $param['client_id'];
//                    $device_id = $param['device_id'];
//                    $wsy_printset = $this->getprintid($mid);
////                    329745
//                    $appid = $wsy_printset['appid'];
//                    $key = $wsy_printset['key'];
//                    $ApiPrint = new ApiPrint();
//
//                    $keys = $ApiPrint->getparam($client_id, $device_id, $appid, $key);
//                    $info = $ApiPrint->wsyprint($paramd, $keys);
                    //接口打印结束135479723636597596
                } elseif ($data['result_code'] == "USERPAYING") {

                    $re_param['return_code'] = $data['return_code'];
                    $re_param['result_code'] = $data['result_code'];
                    $re_param['result_msg'] = $data['result_msg'];
                    $re_param['return_msg'] = $data['return_msg'];
                    $re_param['outTradeNo'] = $param['outTradeNo'];
                    $re_param['tradeNo'] = $data['out_trade_no'];
                    $payinfo = Paylog::where(array('orderid' => $data['out_trade_no']))->find();
                    $re_param['totalFee'] = $payinfo['price'] * 100;//应付
                    $re_param['ought_price'] = $payinfo['yf_price'] * 100;//实付
                    $re_param['dis_card_zk'] = isset($payinfo['dis_card_zk']) ? $payinfo['dis_card_zk'] * 100 : "";//会员卡折扣
                    $re_param['vip_card_zk'] = isset($payinfo['vip_card_zk']) ? $payinfo['vip_card_zk'] * 100 : "";//会员卡等级折扣
                    $re_param['gel_card_zk'] = isset($payinfo['gel_card_zk']) ? $payinfo['gel_card_zk'] * 100 : "";//卡券折扣
                    $re_param['gel_info'] = isset($payinfo['gel_info']) ? $payinfo['gel_info'] : "";    //折扣详情
                    if ($payinfo['pay_fs'] == 2) {
                        $channel = "wx_barcode_pay";
                    } elseif ($payinfo['pay_fs'] == 3) {
                        $channel = "ali_barcode_pay";
                    } elseif ($payinfo['pay_fs'] == 8) {
                        $channel = "card_barcode_pay";
                    }
                    $re_param['channel'] = $channel;
//            $re_param['out_transaction_id'] = $data['transaction_id'];
//            $re_param['time_end'] = $data['pay_time'];


                } elseif ($data['result_code'] == "NOTENOUGH") {
                    $dataa = $param;
                    unset($dataa['sign']);
                    $dataa['query_type'] = "pay";
                    $dataa['confirm'] = "yes";
                    $dataa['out_trade_no'] = $data['out_trade_no'];

                    $dataa['sign'] = getsign(uni_array($dataa), "MD5", $this->getappid($mid));

                    $ss = $this->api(json_encode($dataa));

                    $re_param = json_decode($ss, true);

                } else {

                    $re_param['return_code'] = $data['return_code'];
                    $re_param['result_code'] = $data['result_code'];
                    $re_param['result_msg'] = $data['result_msg'];
                    $re_param['return_msg'] = $data['return_msg'];
                }
                break;
            case "checkpay":
                if ($data['result_code'] == "SUCCESS") {
                    $re_param['return_code'] = $data['return_code'];
                    $re_param['result_code'] = $data['result_code'];
                    $re_param['result_msg'] = $data['result_msg'];
                    $re_param['return_msg'] = $data['return_msg'];
                    $re_param['outTradeNo'] = $data['trade_no'];
                    $re_param['tradeNo'] = $data['out_trade_no'];
                    $re_param['dis_card_zk'] = isset($data['dis_card_zk']) ? $data['dis_card_zk'] * 100 : "";//会员卡折扣
                    $re_param['vip_card_zk'] = isset($data['vip_card_zk']) ? $data['vip_card_zk'] * 100 : "";//会员卡等级折扣
                    $re_param['gel_card_zk'] = isset($data['gel_card_zk']) ? $data['gel_card_zk'] * 100 : "";//卡券折扣
                    $re_param['gel_info'] = isset($data['gel_info']) ? $data['gel_info'] : "";    //折扣详情
                    $re_param['totalFee'] = $data['ought_fee'] * 100;//应付
                    $re_param['ought_price'] = $data['total_fee'] * 100;//实付

                    //接口打印开始
                    $paramd['device_id'] = $param['device_id'];
                    $paramd['paytime'] = date('Y-m-d H:i:s', strtotime($data['end_time']));
                    $paramd['merchant'] = $this->getmerchantname($mid);
                    $paramd['out_trade_no'] = $data['trade_no'];
                    $paramd['staff'] = "";
                    $paramd['total_fee'] = $data['total_fee'];
                    if ($data['channel'] == 2) {
                        $channel2 = "微信";
                        $bmp = 1;
                    } elseif ($data['channel'] == 3) {
                        $channel2 = "支付宝";
                        $bmp = 2;
                    } elseif ($data['channel'] == 8) {
                        $channel2 = "会员卡";
                        $bmp = 1;
                    }
                    $paramd['paymode'] = $channel2;
                    $paramd['bmp'] = $bmp;
                    $paramd['yf_price'] = $data['ought_fee'];
                    $paramd['dis_card_zk'] = $re_param['dis_card_zk'];
                    $paramd['vip_card_zk'] = $re_param['vip_card_zk'];
                    $paramd['gel_card_zk'] = $re_param['gel_card_zk'];
                    $paramd['gel_info'] = $re_param['gel_info'];
                    $sedata=$paramd;
                    $sedata['client_id']=$param['client_id'];
                    $sedata['device_id']=$param['device_id'];
                    $sedata['mid']=$mid;
                    $JobTask=new JobTask();
                    $s=$JobTask->mss_send_wsy_print($sedata);
//                    根据参数获取key
//                    $client_id = $param['client_id'];
//                    $device_id = $param['device_id'];
//                    $wsy_printset = $this->getprintid($mid);
////                    329745
//                    file_put_contents('/data2/html/payos/0003.txt',"开始时间：".date('Y-m-d H:i:s'),8);
//                    $appid = $wsy_printset['appid'];
//                    $key = $wsy_printset['key'];
//                    $ApiPrint = new ApiPrint();
//                    $keys = $ApiPrint->getparam($client_id, $device_id, $appid, $key);
//
//                    $info = $ApiPrint->wsyprint($paramd, $keys);
//                    file_put_contents('/data2/html/payos/0003.txt',"结束时间：".date('Y-m-d H:i:s')."-".json_encode($info),8);
//

                    //接口打印结束
                    if ($data['channel'] == 2) {
                        $channel = "wx_barcode_pay";
                    } elseif ($data['channel'] == 3) {
                        $channel = "ali_barcode_pay";
                    } elseif ($data['channel'] == 8) {
                        $channel = "card_barcode_pay";
                    }
                    $re_param['channel'] = $channel;
                    $re_param['out_transaction_id'] = $data['out_trade_no'];
                    $re_param['outTradeNo'] = $data['trade_no'];

                    $re_param['time_end'] = date('YmdHis', strtotime($data['end_time']));
                } elseif ($data['result_code'] == "USERPAYING") {
                    $re_param['return_code'] = $data['return_code'];
                    $re_param['result_code'] = $data['result_code'];
                    $re_param['result_msg'] = $data['result_msg'];
                    $re_param['return_msg'] = $data['return_msg'];
                    $re_param['outTradeNo'] = $data['trade_no'];
                    $re_param['tradeNo'] = $data['out_trade_no'];
                    $re_param['totalFee'] = $data['ought_fee'] * 100;//应付
                    $re_param['ought_price'] = $data['total_fee'] * 100;//实付
                    $re_param['dis_card_zk'] = isset($data['dis_card_zk']) ? $data['dis_card_zk'] * 100 : "";//会员卡折扣
                    $re_param['vip_card_zk'] = isset($data['vip_card_zk']) ? $data['vip_card_zk'] * 100 : "";//会员卡等级折扣
                    $re_param['gel_card_zk'] = isset($data['gel_card_zk']) ? $data['gel_card_zk'] * 100 : "";//卡券折扣
                    $re_param['gel_info'] = isset($data['gel_info']) ? $data['gel_info'] : "";    //折扣详情
                    if ($data['channel'] == 2) {
                        $channel = "wx_barcode_pay";
                    } elseif ($data['channel'] == 3) {
                        $channel = "ali_barcode_pay";
                    } elseif ($data['channel'] == 8) {
                        $channel = "card_barcode_pay";
                    }
                    $re_param['channel'] = $channel;
//            $re_param['out_transaction_id'] = $data['transaction_id'];
//            $re_param['time_end'] = $data['pay_time'];
                    $sign = getsign(uni_array($re_param), "MD5", $this->getappid($mid));
                    $re_param['sign'] = $sign;

                } else {


                    $re_param['return_code'] = $data['return_code'];
                    $re_param['result_code'] = $data['result_code'];
                    $re_param['result_msg'] = $data['result_msg'];
                    $re_param['return_msg'] = $data['return_msg'];
                }
                break;
            case "payrefund":
                if ($data['result_code'] == "SUCCESS") {
                    $re_param['return_code'] = $data['return_code'];
                    $re_param['result_code'] = $data['result_code'];
                    $re_param['result_msg'] = $data['result_msg'];
                    $re_param['return_msg'] = $data['return_msg'];
                    $re_param['outTradeNo'] = isset($data['trade_no']) ? $data['trade_no'] : "";
                    $re_param['out_transaction_id'] = $data['out_trade_no'];
                    $re_param['refundNo'] = $param['refundNo'];
                    $re_param['refundFee'] = $data['refund_fee'] * 100;
                    if ($data['channel'] == 2) {
                        $channel = "wx_barcode_pay";
                    } elseif ($data['channel'] == 3) {
                        $channel = "ali_barcode_pay";
                    } elseif ($data['channel'] == 8) {
                        $channel = "card_barcode_pay";
                    }
                    $re_param['channel'] = $channel;

                } else {
                    $re_param['return_code'] = $data['return_code'];
                    $re_param['result_code'] = $data['result_code'];
                    $re_param['result_msg'] = $data['result_msg'];
                    $re_param['return_msg'] = $data['return_msg'];
                }
                break;
            case "payrefundquery":
                if ($data['result_code'] == "SUCCESS") {
                    $re_param['return_code'] = $data['return_code'];
                    $re_param['result_code'] = $data['result_code'];
                    $re_param['result_msg'] = $data['result_msg'];
                    $re_param['return_msg'] = $data['return_msg'];
                    $re_param['outTradeNo'] = $data['trade_no'];
                    $re_param['out_transaction_id'] = $data['out_trade_no'];
                    if ($data['channel'] == 2) {
                        $channel = "wx_barcode_pay";
                    } elseif ($data['channel'] == 3) {
                        $channel = "ali_barcode_pay";
                    } elseif ($data['channel'] == 8) {
                        $channel = "card_barcode_pay";
                    }
                    $re_param['channel'] = $channel;
                    $re_param['refundNo'] = $data['refund_no'];
                    $re_param['refundFee'] = $data['refund_fee'] * 100;
                } else {
                    $re_param['return_code'] = $data['return_code'];
                    $re_param['result_code'] = $data['result_code'];
                    $re_param['result_msg'] = $data['result_msg'];
                    $re_param['return_msg'] = $data['return_msg'];
                }
                break;

        }
        $sign = getsign(uni_array($re_param), "MD5", $this->getappid($mid));
        $re_param['sign'] = $sign;
        return $re_param;


    }


    private function http_post($url, $param, $post_file = false)
    {
        $oCurl = curl_init();
        if (stripos($url, "https://") !== FALSE) {
            curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
        }
        if (PHP_VERSION_ID >= 50500 && class_exists('\CURLFile')) {
            $is_curlFile = true;
        } else {
            $is_curlFile = false;
            if (defined('CURLOPT_SAFE_UPLOAD')) {
                curl_setopt($oCurl, CURLOPT_SAFE_UPLOAD, false);
            }
        }
        if (is_string($param)) {
            $strPOST = $param;
        } elseif ($post_file) {

            if ($is_curlFile) {
                foreach ($param as $key => $val) {

                    if (substr($val, 0, 1) == '@') {

                        $param[$key] = new \CURLFile(realpath(substr($val, 1)));

                    }
                }

            }
            $strPOST = $param;

        } else {
            $aPOST = array();
            foreach ($param as $key => $val) {
                $aPOST[] = $key . "=" . urlencode($val);
            }
            $strPOST = join("&", $aPOST);

        }

        curl_setopt($oCurl, CURLOPT_URL, $url);
        curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($oCurl, CURLOPT_POST, true);
        curl_setopt($oCurl, CURLOPT_POSTFIELDS, $strPOST);
        curl_setopt($oCurl, CURLOPT_HTTPHEADER, array('Content-Type:application/json; charset=utf-8',

            'Content-Length: ' . strlen($param)));
        $sContent = curl_exec($oCurl);
        $aStatus = curl_getinfo($oCurl);
        curl_close($oCurl);

        if (intval($aStatus["http_code"]) == 200) {
            return $sContent;
        } else {
            return false;
        }
    }
}